define(function (require, exports, module) {

    function RightCtrol(opt) {
        if (!(this instanceof RightCtrol)) {
            return new RightCtrol(opt);
        }

        // this.

        this.startY = 0;
        this.moveY = 0;
        this.translateYValue = 0;


    }

    RightCtrol.prototype = {
        init: function () {
            console.log('右侧数据', window.getInfoId);

            // this.setTouchEvent();
        },
        setTouchEvent: function () {
            var rightDom = $(".layout-right");

            
            rightDom.off('touchstart').on('touchstart', function (e) {
                
                this.startY = e.touches[0].pageY;
            })

            rightDom.off('touchmove').on('touchmove', function (e) {

                console.log(rightDom.height(), 'rightDom.height()');

                if (rightDom.height() < $(window).height()) {
                    return;
                } else {
                    this.moveY = e.touches[0].pageY;
                    this.translateYValue += this.moveY - this.startY;
                    if (this.translateYValue > 150) {
                        this.translateYValue = 150;
                    }

                    if (rightDom.height() - $(window).height() < Math.abs(this.translateYValue)) {

                        this.translateYValue = -(rightDom.height() - $(window).height());
                    }
                    this.moveMenu();
                }
            }.bind(this))


            rightDom.off('touchend').on('touchend', function (e) {

                if (rightDom.height() < $(window).height()) {
                    return;
                } else {
                    if (this.translateYValue > 0) {
                        this.translateYValue = 0;
                    }
                    this.moveMenu();
                }


            }.bind(this));

        },

        moveMenu: function () {
            var rightDom = $(".layout-right");
            rightDom[0].style.transform = "translateY(" + this.translateYValue + "px)";
        },
        getData: function () {
            var menuInfo = $('.menu-info');

            var html = '';
            $.ajax({
                url: 'http://youyong.ba:8080/mock/5fed6c290d6d9c4f58824008/category-info?id=' + window.getInfoId,
                success: function (res) {
                    var db = TAFFY(res.data);

                    var group = db().distinct("typeName");
                    var arr = [];
                    for (var i = 0; i < group.length; i++) {
                        arr.push(db({ 'typeName': group[i] }).get());
                    }

                    var html = '';
                    for (var i = 0; i < arr.length; i++) {
                        if (i == arr.length - 1 ) {
                            html += '<div class="menu-info-item" style="padding-bottom:3rem">';

                        } else {
                            html += '<div class="menu-info-item">';

                        }

                        html += '<h3 class="menu-info-item-hd">';
                        html += group[i];
                        html += '</h3>';

                        html += '<ul class="menu-info-item-bd">';

                        for (var j = 0; j < arr[i].length; j++) {

                            html += '<li class="menu-info-item-bd-item">' +
                                '<a href="">' +
                                '<img src="' + arr[i][j].img + '"/>' +
                                '<h4>' + arr[i][j].title + '</h4>' +
                                '</a>' +
                                '</li>';
                        }
                        html += '</ul>';
                        html += '</div>';
                    }

                    menuInfo.html(html);
                }
            });
        }
    }


    module.exports = RightCtrol;


});